package cn.sofwin.day0204.homework;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;

public class H2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入年份：");
        int year = sc.nextInt();
        System.out.print("请输入月份：");
        int month = sc.nextInt();
        System.out.print("请输入日期：");
        int day = sc.nextInt();

        // 本月1号
        LocalDate firstDayOfMonth = LocalDate.of(year, month, 1);
        // 本年本月1号对应星期几
        int firstDayOfWeek = firstDayOfMonth.getDayOfWeek().getValue();

        System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
        // 第一周日历空格部分
        for (int i = 0; i < firstDayOfWeek; i++) {
            System.out.print("\t\t");
        }
        // 第一周日历非空格部分
        for (int i = 1; i <= 7 - firstDayOfWeek; i++) {
            if (i == day){
                System.out.print(i + "*");
            }else {
                System.out.print(i);
            }
            if (7 - firstDayOfWeek - i > 0){
                System.out.print("\t\t");
            }else if (7 - firstDayOfWeek - i == 0){
                System.out.println();
            }
        }

        // 本月有多少天
        int lastDayOfMonth = firstDayOfMonth.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
        // 除第一周以外本月日历
        int flag = 0;
        for (int i = 7 - firstDayOfWeek + 1; i <= lastDayOfMonth; i++) {
            if (i == day){
                System.out.print(i + "*");
            }else {
                System.out.print(i);
            }
            flag++;
            if (flag < 7){
                System.out.print("\t\t");
            }else if (flag == 7){
                System.out.println();
                flag = 0;
            }
        }
    }
}